# Tweaks

This file lists some configuration file tweaks, performance tweaks, visual tweaks, and the likes of making your game run better.

## Performance tweaks

Please keep in mind that the minimal specifications also apply for Linux. Do not expect a performance gain compared to Windows native.

As of game version 3.2.0, it is recommended to apply the secondary patch to noticeably
lower the CPU usage. Please check Issue #195 and the script source for details.

	bash "/path/to/dawn/GAMEVER/patch_anti_logincrash.sh"


#### DXVK

Check whether the latest DXVK version is installed in your `WINEPREFIX`:

* Use default `WINEDEBUG` (no `-all`!) and check the (terminal) output
* `output_log.txt` ([what?](FAQ.md)) should mention DXVK

Setup instructions: [TROUBLESHOOTING.md](TROUBLESHOOTING.md#graphics-bugsissues)


#### Esync

Esync will sometimes work faster than Fsync on some specific game/machine combinations ([see here](https://flightlessmango.com/benchmarks/Esync_vs_Fsync)).

Please note that the official Wine builds do not come with Esync support.
One of the following builds is required:

**Lutris:**

 * Select game -> Configure -> Runner options -> "Enable Esync"
 * See also: [Official tutorial](https://github.com/lutris/docs/blob/master/HowToEsync.md)

**Proton:**

 * Enabled by default when running from the Steam library

**wine-staging or custom build:**

 * Add `export WINEESYNC=1` to your script prior to launching the game

If you have access to the terminal output (or logs), look out for
`esync: up and running.` mentions to confirm that it's working.


#### AMD GPU performance tweaks

This section is about reducing choppy framerates on amdgpu + radv.
According to Issue #321 the GPU might not boost the clocks properly.

*Note: This also affects other games and might be fixed in future driver updates.*

 * Hardware configuration (`amdgpu` driver specific)
     * Note: The kernel settings are not persistent and will reset on reboot.
     * For details: [amdgpu kernel documentation](https://kernel.org/doc/html/latest/gpu/amdgpu/thermal.html#power-dpm-force-performance-level)
     * `echo 1 | sudo tee /sys/class/drm/card0/device/pp_power_profile_mode`
         * Improves performance on adaptive sync displays
     * `echo high | sudo tee /sys/class/drm/card0/device/power_dpm_force_performance_level`
         * Might not be needed any more for recent driver versions.
     * For `gamemode` users:
         1. Edit the configuration file.
         2. Add the line `amd_performance_level=high` to the `[gpu]` configuration section.
 * Game settings
     * Render Resolution: 1.0
     * Shadow Quality: Low
     * Volumetric Fog: Off
     * V-Sync: On (avoids tearing)

For Arch Linux: Steam installs the dependencies `amdvlk` and `lib32-amdvlk` by default.
This might cause performance or game startup issues in general. To use RADV (provided by Mesa),
uninstall both libraries. Run a Vulkan verification test after rebooting.

 * For details, see [Vulkan, Arch Wiki](https://wiki.archlinux.org/title/Vulkan)


#### GPU bottleneck improvements

 * Stutter and low FPS on GPUs with <= 2 GB VRAM
    * For monitoring: `nvidia-smi`/`nvtop` (nVIDIA), `radeontop` (AMD), `corectrl` (AMD)
    * Use a DXVK 1.X.X version, 1.9.4 or newer (memory management improvements)
    * In-game setting: Change "Render Resolution" to 0.8 or lower
        * This setting changes the texture resolution, resulting in less VRAM usage
    * Disable Anti-Aliasing (less blur)
    * Close `zfgamebrowser.exe` to free approx. 60 MB (after DXVK 1.9.4)
 * In-game setting: Disable "Volumetric Fog". Introduces more lag than what's worth it
 * In-game setting: Lower "Shadow Quality". May improve the frame rates
 * Create a file named `dxvk.conf` where `GenshinImpact.exe` resides. Example options for vsync-less (mailbox mode), tearing-free, low latency gameplay:

```
# Change to 3 for triple buffering (improves performance at the cost of latency)
dxgi.numBackBuffers = 2
dxgi.syncInterval = 0
dxgi.tearFree = True
# More performance
d3d11.constantBufferRangeCheck = False
d3d11.relaxedBarriers = True
d3d11.invariantPosition = False
d3d11.zeroWorkgroupMemory = False
```

Also the environment variable `DXVK_ASYNC=1` might help to reduce stutters. This
feature is not available by default and requires a [special DXVK patch](https://github.com/Sporif/dxvk-async).


#### FSR - FidelityFX Super Resolution

FSR is an image upscaler which can improve game performance.
See [AMD website](https://www.amd.com/en/technologies/radeon-software-fidelityfx-super-resolution) for details.

The following two sections each describe a method to get FSR running.

##### FSR with Gamescope

Links for reference:

 * [gamescope project site](https://github.com/Plagman/gamescope)
 * [LinuxReviews testing report](https://linuxreviews.org/Gamescope)

**Caveats:**

 * Requires a native window (no virtual desktop)
 * At the time of writing, it requires recent driver packages.
     * Pleas refer to the project site for details
 * Causes input lag and mouse cursor behaviour is not ideal
 * Package not present in some distributions' repositories

To benefit from improvements in newer Wine/Proton versions, gamescope is
designed as a long-term solution.

General features:

 * Graphic environment independent
 * Custom upscaling / downscaling of any game running inside of it
 * UI integration in some game launchers, such as Lutris

Command line example:

	# General syntax
	gamescope -w <game_visible_width> -h <game_visible_height> -W <final_window_width> -H <final_window_height> -U -f -- <command>
	# Example for upscaling 1080p -> 1440p
	gamescope -w 1920 -h 1080  -W 2560 -H 1440 -U -f -- wine cmd /c launcher.bat -window-mode exclusive

 * Notes
     * `-f` means Gamescope window will be fullscreen at startup.
       You want that for Variable Refresh Rate (Free/G/Sync).
     * `Super + F` can be used to switch between Fullscreen/Window for Gamescope output.
     * Once windowed, Gamescope output can be resized but blackbars may appear
     * Please refer to the project site for further tweaking


##### FSR bundled with Wine

**Caveats:**

 * Requires a native window (no virtual desktop)
 * Resolution changes must be done in windowed mode or by command line arguments
    * Use `Alt+Enter` to switch between windowed and fullscreen

Wine builds known to embed the feature at this moment are:

 * proton-ge-custom
 * wine-ge-custom
 * Kron4ek's Wine builds
     * Supported versions to be checked.

Required command line arguments:

 * Append `-window-mode exclusive` after `launcher.bat`
    * Example: `??? cmd /c launcher.bat -window-mode exclusive`

Configuration via environment variables: (example values are the default)

 * `WINE_FULLSCREEN_FSR=1` -> enables FSR
 * `WINE_FULLSCREEN_FSR_MODE=balanced`
    * One of `ultra`, `quality`, `balanced` or `performance`
 * `WINE_FULLSCREEN_FSR_STRENGTH=2` -> values from 0 (sharp) to 5 (blurry)
 * Instructions:
    * Steam: adjust the `Target` box. Example: `FOO=1 BAR=1 cmd.exe`
    * Lutris: add rows to `Configuration` -> `System options` -> `Environment variables`

Checking whether FSR is enabled:

1. Specify the environment variable `WINEDEBUG=trace+fshack`.
2. The line `trace:fshack:fs_hack_is_fsr is_fsr: TRUE` must appear in the Wine output.


#### Loading times

This is an optimization for installations on a slow drive.
You may make Linux' file caching to RAM more aggressive in order reduce loading
times for repetitive actions.

1. Open `/etc/sysctl.conf` with an editor like `nano` with sudo.
2. Add the line `vm.vfs_cache_pressure = 10`. Save and exit.
3. Run `sudo sysctl -p` to reload the kernel configuration.


## Visual tweaks

#### Benchmark

* Set the environment variable `DXVK_HUD` to `fps,frametimes`
* For a fancier display, try [MangoHud](https://github.com/flightlessmango/MangoHud) instead.


#### Post Processing using vkBasalt

[vkBasalt](https://github.com/DadSchoorse/vkBasalt) offers cool shaders and re-shade-like features.

1. Disable in-game antialiasing
2. Create a file named `vkBasalt.conf` in the directory where `GenshinImpact.exe` resides.
3. Relevant information and examples:
    * Detailed descriptions: [official `vkBasalt.conf`](https://github.com/DadSchoorse/vkBasalt/blob/master/config/vkBasalt.conf)
    * Presets by notahuman: [Releases page](https://notabug.org/notahuman/presets/releases)
    * Other user-provided presets: [static/](static/)
